package cn.gson.fengboot.model.service;

import cn.gson.fengboot.model.dao.LtousuDao;
import cn.gson.fengboot.model.mapper.LtousuMapper;
import cn.gson.fengboot.model.pojos.Ltousu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.*;

@Service
@Transactional(rollbackFor =  Exception.class)
public class LtousuService {
    @Autowired
    LtousuMapper ltousuMapper;
    @Autowired
    LtousuDao ltousuDao;


    //查询所有客户服务
    public List<Ltousu> khtousu(String search,String fenlei){
        return ltousuMapper.khtousu(search,fenlei);
    }


    @Transactional(transactionManager = "transactionManager")
    //新增投诉意见
    public  void addkhtousu(Ltousu ltousu){
       ltousuDao.save(ltousu);

    }

    //查询圆形类型统计图
    public Map<String ,Object> tousulx(){
        List<Ltousu> lxname=ltousuMapper.tousulx();
        Map<String,Object> map=new HashMap<>();
        List<String> lei =new ArrayList<>();//类型
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            lei.add(lxname.get(i).getTsFenglei());
            shul.add(ltousuDao.lxcs(lxname.get(i).getTsFenglei()));
        }
        map.put("lei",lei);
        map.put("shul",shul);
        return map;
    }

    //查询圆形花费时间统计图
    public Map<String ,Object> hfsj(){
        List<Ltousu> lxname=ltousuMapper.hfsjlx();
        Map<String,Object> map=new HashMap<>();
        List<String> lei =new ArrayList<>();//类型
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            lei.add(lxname.get(i).getTsHuafeitime());
            shul.add(ltousuDao.hfsjcs(lxname.get(i).getTsHuafeitime()));
        }
        map.put("lei",lei);
        map.put("shul",shul);
        return map;
    }

    //查询月度客户投诉
    public  Map<String ,Object> ydtsfb(){
        Map<String,Object> map=new HashMap<>();
        List<Integer> shul=ltousuDao.ydtsfb();//数量
        List<String> shul1=ltousuDao.ydtsfb1();//
        System.out.println(shul1);
        map.put("shul",shul);
        map.put("shul1",shul1);
        return map;
    }

    //柱形统计图投诉客户投诉分布查询
    public Map<String ,Object> khtsfb(){
        List<Ltousu> lxname=ltousuMapper.khtsfb();
        Map<String,Object> map=new HashMap<>();
        List<String> shul1 =new ArrayList<>();//
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getClientId().getClientName());
            shul.add(ltousuDao.khtsfb(lxname.get(i).getClientId().getClientName()));
        }
        map.put("shul",shul);
        map.put("shul1",shul1);
        return map;
    }


    //折线
    public Map<String ,Object> zhexian(){
        Map<String,Object> map=new HashMap<>();
        List<Ltousu> lxname=ltousuMapper.zxian();
        List<String> shul1 =new ArrayList<>();//
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getTsJinjichendu());
            shul.add(ltousuDao.zhexian(lxname.get(i).getTsJinjichendu()));
        }
        map.put("shul",shul);
        map.put("shul1",shul1);
        return map;
    }

    //折线
    public Map<String ,Object> zhexian1(){
        Map<String,Object> map=new HashMap<>();
        List<Ltousu> lxname=ltousuMapper.zxian();
        List<String> shul1 =new ArrayList<>();//
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getTsChulijieguo());
            shul.add(ltousuDao.zhexian1(lxname.get(i).getTsChulijieguo()));
        }
        map.put("shul",shul);
        map.put("shul1",shul1);
        return map;
    }

    //<!--谭方圆=>客户合并的客户投诉查询-->
    public List<Ltousu> tfytousu(Integer id1, Integer id2){
        return ltousuMapper.tfytousu(id1,id2);
    }






}
